package com.wenzhiguo.myheadline.fragment;


import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.wenzhiguo.lazyviewpager.LazyFragmentPagerAdapter;
import com.wenzhiguo.lazyviewpager.LazyViewPager;
import com.wenzhiguo.myheadline.R;
import com.wenzhiguo.pagerslidingtabstrip.PagerSlidingTabStrip;


public class HomeFragment extends Fragment {

    private PagerSlidingTabStrip sliding;
    private LazyViewPager lazy;
    private View view;

    public HomeFragment() {
    }


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        view = inflater.inflate(R.layout.fragment_home, container, false);
        //控件
        initView();
        //适配器
        setAdapter();
        return view;
    }

    private void initView() {
        sliding = (PagerSlidingTabStrip) view.findViewById(R.id.psts);
        lazy = (LazyViewPager) view.findViewById(R.id.lvp);
    }

    private void setAdapter() {
        lazy.setAdapter(new MyAdapter(getActivity().getSupportFragmentManager()));
        sliding.setViewPager(lazy);
    }

    class MyAdapter extends LazyFragmentPagerAdapter {
        String[] titles = new String[]{"精选", "足球", "娱乐", "体育", "财经", "科技", "电影",
                "NBA", "教育", "论坛", "情感", "时尚", "电台", "彩票", "汽车", "游戏", "笑话"};
        String[] id = new String[]{"T1370583240249", "T1399700447917", "T1348648517839",
                "T1348649079062", "T1348648756099", "T1348649580692", "T1348648650048",
                "T1348649145984", "T1348654225495", "T1349837670307", "T1348650839000",
                "T1348650593803", "T1379038288239", "T1356600029035", "T1348654060988",
                "T1348654151579", "T1350383429665"};

        public MyAdapter(FragmentManager fm) {
            super(fm);
        }

        @Override
        protected Fragment getItem(ViewGroup container, int position) {
            return NewFragment.newInstance(position + "", id[position]);
        }

        @Override
        public CharSequence getPageTitle(int position) {
            return titles[position];
        }

        @Override
        public int getCount() {
            return titles.length;
        }
    }
}
